package com.skycode7.servlet;

import com.skycode7.bean.AdminBean;
import com.skycode7.dao.AdminDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet("/adminEdit.jsp")
public class AdminEditServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String adminID =req.getParameter("AdminID");
        String adminTitle = req.getParameter("AdminTitle");
        String adminContent = req.getParameter("AdminContent");
        AdminBean adminBean = new AdminBean();
        adminBean.setAdminID(Integer.parseInt(adminID));
        AdminBean.setAdminTitle(adminTitle);
        adminBean.setAdminContent(adminContent);
        adminBean.setAdminTime((new Date()).toString());
        adminBean.setAdminName("admin");
        int result = (new AdminDao()).updateAdmin();
        if(result >0){
            resp.sendRedirect("admin.html");
        }else{
            req.getRequestDispatcher("adminEdit.jsp").forward(req, resp);
        }
    }

    private HttpServletRequest setCharacterEncoding(String s) {
        return null;
    }
}
